package top.naccl.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;
import top.naccl.model.vo.UploadResult;
import top.naccl.service.UploadService;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.HashMap;

/**
 * @description:vditor上传控制器
 * @package top.naccl.controller.admin
 * @who MiaoMiao "Sprout" BI
 * @date 2021-01-29 09:33:19
 */
@RestController
@RequestMapping("/admin")
public class ImageController {
    @Autowired
    UploadService uploadService;


    @PostMapping("/imageUpload")
    public String upload(HttpServletRequest request) throws IOException {
        MultipartRequest multipartRequest= (MultipartRequest) request;
        MultipartFile file = multipartRequest.getFile("file[]");
        String filename = file.getOriginalFilename();
        String upload = uploadService.upload(filename, file);



//        UploadResult uploadResult = new UploadResult();
//        uploadResult.setCode(0);
//        uploadResult.setMsg("");
//        uploadResult.setName(upload);
        return upload;
    }

    @PostMapping("/fetch")
    public String fetch(MultipartFile name,String filename) throws IOException {
        return uploadService.upload(filename,name);
    }


}
